home *** CD-ROM | disk | FTP | other *** search
-
- /*⌐ Copyright 1988-1991 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include "appletinternal.h"
- #include "font.h"
- #include "quickdraw.h"
-
-
- #define ctpens 5 /*we can remember pens up to 5 levels deep*/
-
- short toppens = 0;
-
- PenState penstack [ctpens];
-
-
- #define ctports 5 /*we can remember ports up to 5 levels deep*/
-
- short topport = 0;
-
- GrafPtr portstack [ctports];
-
-
- #define ctclip 5 /*we can remember clips up to 5 levels deep*/
-
- short topclip = 0;
-
- Rect clipstack [ctclip];
-
-
- #define ctstyle 5 /*we can remember font/size/styles up to 5 levels deep*/
-
- short topstyle = 0;
-
- struct {short fnum, fsize, fstyle;} stylestack [ctstyle];
-
-
- boolean pushpen () {
-
- if (toppens >= ctpens)
- return (false);
-
- GetPenState (&penstack [toppens++]);
-
- return (true);
- } /*pushpen*/
-
-
- boolean poppen () {
-
- if (toppens <= 0)
- return (false);
-
- SetPenState (&penstack [--toppens]);
-
- return (true);
- } /*poppen*/
-
-
- boolean pushmacport (p) GrafPtr p; {
-
- if (topport >= ctports) {
-
- DebugStr ((ConstStr255Param)"\ppushmacport: no room on stack");
-
- return (false);
- }
-
- portstack [topport++] = quickdrawglobal (thePort);
-
- if (p != nil)
- SetPort (p);
-
- return (true);
- } /*pushmacport*/
-
-
- boolean popmacport () {
-
- if (topport <= 0) {
-
- DebugStr ((ConstStr255Param)"\ppopmacport: nothing on stack");
-
- return (false);
- }
-
- SetPort (portstack [--topport]);
-
- return (true);
- } /*popmacport*/
-
-
- boolean pushclip (r) Rect r; {
-
- register RgnHandle rgn;
-
- if (topclip >= ctclip)
- return (false);
-
- GetClip (rgn = NewRgn ());
-
- clipstack [topclip++] = (**rgn).rgnBBox;
-
- DisposeRgn (rgn);
-
- ClipRect (&r);
-
- return (true);
- } /*pushclip*/
-
-
- boolean popclip () {
-
- if (topclip <= 0)
- return (false);
-
- ClipRect (&clipstack [--topclip]);
-
- return (true);
- } /*popclip*/
-
-
- boolean pushstyle (fnum, fsize, fstyle) short fnum, fsize, fstyle; {
-
- if (topstyle >= ctstyle)
- return (false);
-
- getfontsizestyle (
- &stylestack [topstyle].fnum,
-
- &stylestack [topstyle].fsize,
-
- &stylestack [topstyle].fstyle);
-
- topstyle++;
-
- setglobalfontsizestyle (fnum, fsize, fstyle);
-
- return (true);
- } /*pushstyle*/
-
-
- boolean popstyle (void) {
-
- if (topstyle <= 0)
- return (false);
-
- topstyle--;
-
- setfontsizestyle (
- stylestack [topstyle].fnum,
-
- stylestack [topstyle].fsize,
-
- stylestack [topstyle].fstyle);
-
- return (true);
- } /*popstyle*/
-
-
- short getmenubarheight (void) {
-
- return (GetMBarHeight ()); /*call Script Manager routine*/
- } /*getmenubarheight*/
-
-
- void localtoglobalrect (Rect *rchanged) {
-
- Point p1, p2;
- Rect r;
-
- r = *rchanged;
-
- p1.h = r.left;
-
- p1.v = r.top;
-
- LocalToGlobal (&p1);
-
- p2.h = r.right;
-
- p2.v = r.bottom;
-
- LocalToGlobal (&p2);
-
- Pt2Rect (p1, p2, &r);
-
- *rchanged = r;
- } /*localtoglobalrect*/
-
-
- void eraserect (r) Rect r; {
-
- EraseRect (&r);
- } /*eraserect*/
-
-
- void invalrect (r) Rect r; {
-
- InvalRect (&r);
- } /*invalrect*/
-
-
- static short absint (short x) {
-
- if (x < 0)
- x = -x;
-
- return (x);
- } /*absint*/
-
-
- short pointdist (Point pt1, Point pt2) {
-
- return (absint (pt1.h - pt2.h) + absint (pt1.v - pt2.v));
- } /*pointdist*/
-
-
- void centerrect (Rect *rcentered, Rect rcontains) {
-
- /*
- center the first rectangle within the second rectangle.
- */
-
- register short height, width;
- Rect r;
-
- r = *rcentered;
-
- width = r.right - r.left;
-
- r.left = rcontains.left + ((rcontains.right - rcontains.left - width) / 2);
-
- r.right = r.left + width;
-
- height = r.bottom - r.top;
-
- r.top = rcontains.top + ((rcontains.bottom - rcontains.top - height) / 2);
-
- r.bottom = r.top + height;
-
- *rcentered = r;
- } /*centerrect*/
-
-
-
-
-
-
-
-